//
//  UIView+PACAAlignment.m
//  高德SDK
//
//  Created by rainimute on 16/8/31.
//  Copyright © 2016年 你问我答. All rights reserved.
//

#import "UIView+PACAAlignment.h"

@implementation UIView (PACAAlignment)

- (void)centerToAnotherView:(UIView*)otherView{
    self.center = otherView.center;
}

- (void)centerYToAnotherView:(UIView*)otherView{
    CGPoint selfCenter = self.center;
    selfCenter.y = otherView.center.y;
    self.center = selfCenter;
}

- (void)centerInSuperView:(UIView *)superView{
    self.center = CGPointMake(superView.frame.size.width/2, superView.frame.size.height/2);
}

- (void)centerYInSuperView:(UIView *)superView{
    CGPoint selfCenter = self.center;
    selfCenter.y = superView.frame.size.height/2;
    self.center = selfCenter;
}

- (void)centerYInSuperView:(UIView *)superView ratio:(double)ratio{
    CGPoint selfCenter = self.center;
    selfCenter.y = superView.frame.size.height*ratio;
    self.center = selfCenter;
}

- (void)centerYInSuperView:(UIView*)superView distance:(float)distance{
    CGPoint selfCenter = self.center;
    selfCenter.y = superView.frame.size.height/2 + distance;
    self.center = selfCenter;
}

- (void)centerXToAnotherView:(UIView*)otherView{
    CGPoint selfCenter = self.center;
    selfCenter.x = otherView.center.x;
    self.center = selfCenter;
}

- (void)centerXInSuperView:(UIView *)superView{
    CGPoint selfCenter = self.center;
    selfCenter.x = superView.frame.size.width/2;
    self.center = selfCenter;
}

- (void)centerXInSuperView:(UIView *)superView ratio:(double)ratio{
    CGPoint selfCenter = self.center;
    selfCenter.x = superView.frame.size.width*ratio;
    self.center = selfCenter;
}

- (void)centerXInSuperView:(UIView*)superView distance:(float)distance{
    CGPoint selfCenter = self.center;
    selfCenter.x = superView.frame.size.width/2 + distance;
    self.center = selfCenter;
}

- (void)centerYDistanceToAnotherView:(UIView *)otherView distance:(float)distance{
    CGPoint selfCenter = self.center;
    selfCenter = CGPointMake(otherView.center.x, otherView.center.y+distance);
    self.center = selfCenter;
}

- (void)centerXDistanceToAnotherView:(UIView *)otherView distance:(float)distance{
    CGPoint selfCenter = self.center;
    selfCenter = CGPointMake(otherView.center.x+distance, otherView.center.y);
    self.center = selfCenter;
}

- (void)leftDistanceToAnotherView:(UIView*)otherView distance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.x = otherView.frame.origin.x + otherView.frame.size.width + distance;
    self.frame = selfFrame;
}

- (void)leftDistanceToAnotherView:(UIView*)otherView leftDistance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.x = otherView.frame.origin.x + distance;
    self.frame = selfFrame;
}

- (void)rightDistanceToAnotherView:(UIView*)otherView distance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.x = otherView.frame.origin.x - distance - selfFrame.size.width;
    self.frame = selfFrame;
}

- (void)rightDistanceToAnotherView:(UIView*)otherView rightDistance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.x = otherView.frame.origin.x + otherView.frame.size.width + distance - selfFrame.size.width;
    self.frame = selfFrame;
}

- (void)upDistanceToAnotherView:(UIView*)otherView distance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.y = otherView.frame.origin.y + otherView.frame.size.height + distance;
    self.frame = selfFrame;
}

- (void)upDistanceToAnotherView:(UIView*)otherView upDistance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.y = otherView.frame.origin.y + distance;
    self.frame = selfFrame;
}

- (void)downDistanceToAnotherView:(UIView*)otherView distance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.y = otherView.frame.origin.y - distance - selfFrame.size.height;
    self.frame = selfFrame;
}

- (void)downDistanceToAnotherView:(UIView*)otherView downDistance:(float)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.y = otherView.frame.origin.y + otherView.frame.size.height + distance - selfFrame.size.height;
    self.frame = selfFrame;
}

/*改变x*/
- (void)changeXToOtherX:(CGFloat)x{
    CGRect selfFrame = self.frame;
    selfFrame.origin.x = x;
    self.frame = selfFrame;
}
/*改变y*/
- (void)changeYToOtherY:(CGFloat)y{
    CGRect selfFrame = self.frame;
    selfFrame.origin.y = y;
    self.frame = selfFrame;
}
/*改变width*/
- (void)changeWidthToOtherWidth:(CGFloat)width{
    CGRect selfFrame = self.frame;
    selfFrame.size.width = width;
    self.frame = selfFrame;
}
/*改变height*/
- (void)changeHeightToOtherHeight:(CGFloat)height{
    CGRect selfFrame = self.frame;
    selfFrame.size.height = height;
    self.frame = selfFrame;
}
/*修改x*/
- (void)changeXWithDistance:(CGFloat)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.x += distance;
    self.frame = selfFrame;
}
/*修改y*/
- (void)changeYWithDistance:(CGFloat)distance{
    CGRect selfFrame = self.frame;
    selfFrame.origin.y += distance;
    self.frame = selfFrame;
}
/*修改width*/
- (void)changeWidthWithDistance:(CGFloat)distance{
    CGRect selfFrame = self.frame;
    selfFrame.size.width += distance;
    self.frame = selfFrame;
}
/*修改height*/
- (void)changeHeightWithDistance:(CGFloat)distance{
    CGRect selfFrame = self.frame;
    selfFrame.size.height += distance;
    self.frame = selfFrame;
}



@end
